/***************************************************************************

-------------------
    begin                : 
    copyright            : kuzkok
    email                : kuzkok at gmail.com

***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*   
*   Данная программа является свободным программным обеспечением;         *
*   Вы можете распространять ее и/или модифицировать в соответствии с     *
*   GNU General Public License опубликованной Фондом свободного           *
*   программного обеспечения; используемая версия лицензии - 2 или        *
*   (по вашему выбору) любая более поздняя                                *
***************************************************************************/

#include "onlinefacility.h"

OnlineFacility::OnlineFacility(QString theTableName) :
    OnlineFeature(theTableName)
{
}

OnlineFacility::OnlineFacility(QUuid theEventID, QString theTableName) :
        OnlineFeature(theEventID, theTableName)
{
    if(mObjectState)
    {
        mInServiceDate = mSelectQuery->value(mSelectQuery->record().indexOf("inservicedate")).toDate();
        mInstallationDate = mSelectQuery->value(mSelectQuery->record().indexOf("installationdate")).toDate();
        mOperationalStatus = mSelectQuery->value(mSelectQuery->record().indexOf("operationalstatus")).toString();
        mSiteEventID = QUuid(mSelectQuery->value(mSelectQuery->record().indexOf("siteeventid")).toString());
    }
}

void OnlineFacility::buildInsertStatement()
{
    OnlineFeature::buildInsertStatement();
    mInsertStatementFields += ", inservicedate"
                             ", installationdate"
                             ", operationalstatus"
                             ", siteventid";
    mInsertStatementValues += ", :inservicedate"
                             ", :installationdate"
                             ", :operationalstatus"
                             ", :siteventid";
}

void OnlineFacility::buildUpdateStatement()
{
    OnlineFeature::buildUpdateStatement();
    mUpdateStatement += ", inservicedate = :inservicedate"
                       ", installationdate = :installationdate"
                       ", operationalstatus = :operationalstatus"
                       ", siteventid = :siteventid";
}

void OnlineFacility::bindQueryValues(QSqlQuery &query)
{
    OnlineFeature::bindQueryValues(query);
    query.bindValue(":inservicedate", mInServiceDate);
    query.bindValue(":installationdate", mInstallationDate);
    query.bindValue(":operationalstatus", mOperationalStatus);
    query.bindValue(":siteeventid", UuidToVariant(mSiteEventID));
}
